"""
文件存储 ORM 模型
"""
from sqlalchemy import String, BigInteger, SmallInteger, Boolean
from sqlalchemy.orm import Mapped, mapped_column

from axiom_boot.core.types import BigInt
from axiom_boot.database import BaseModel


class SysFileStorage(BaseModel):
    """
    文件及文件夹统一存储信息表 ORM 模型。
    采用邻接表模型来表示层级关系。
    """
    __tablename__ = "sys_file_storage"

    # 显式重写 id 以符合【主键覆盖原则】
    id: Mapped[BigInt] = mapped_column(BigInteger, primary_key=True, comment="主键ID (雪花ID)")

    parent_id: Mapped[BigInt | None] = mapped_column(BigInteger, index=True, comment="父文件夹ID，根目录为NULL")

    bucket: Mapped[str] = mapped_column(String(100), nullable=False, index=True, comment="存储桶名称")

    name: Mapped[str] = mapped_column(String(255), nullable=False, comment="文件或文件夹的显示名称")

    is_dir: Mapped[int] = mapped_column(SmallInteger, nullable=False, default=0, comment="是否为文件夹 (0: 否, 1: 是)")

    storage_key: Mapped[str | None] = mapped_column(String(512), nullable=True, unique=True, comment="文件在后端存储的唯一路径或Key (仅文件拥有)")

    provider: Mapped[str | None] = mapped_column(String(50), nullable=True, comment="存储提供商 (e.g., local, s3)")

    mime_type: Mapped[str | None] = mapped_column(String(128), nullable=True, comment="文件的MIME类型")

    size_bytes: Mapped[int | None] = mapped_column(BigInteger, nullable=True, comment="文件大小（字节）") 